/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.unicamp.ic.sgct.client.apresentacao.views;

import br.unicamp.ic.sgct.client.apresentacao.widgets.LabelCampoForm;
import br.unicamp.ic.sgct.client.dominio.to.AreaTO;
import br.unicamp.ic.sgct.client.dominio.to.AutorTO;
import br.unicamp.ic.sgct.client.dominio.to.AvaliacaoTO;
import br.unicamp.ic.sgct.client.dominio.to.CentroConvencaoTO;
import br.unicamp.ic.sgct.client.dominio.to.SubmissaoTO;
import br.unicamp.ic.sgct.client.dominio.to.TrabalhoTO;
import br.unicamp.ic.sgct.client.dominio.to.UsuarioTO;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Grid;
import java.util.List;

/**
 *
 * @author arthur
 */
public class ViewUtil {
    public static String foneMask = "(###) ####-####";
    public static String timeMask = "##/##/####";
    public static String timeFormat = "dd/MM/yyyy";
    public static DateTimeFormat _dtTimeFormat = DateTimeFormat.getFormat(timeFormat);

    public static Grid montarGridCentroConvencao(final CentroConvencaoTO to) {
        Grid grid = new Grid(4, 2);
        if (to != null) {
            grid.setBorderWidth(0);
            grid.setCellSpacing(1);
            grid.setCellPadding(1);
            grid.setTitle("Detalhes confer\u00eancia selecionada...");

            grid.setWidget(0, 0, new LabelCampoForm("Nome"));
            grid.setWidget(1, 0, new LabelCampoForm("Fone"));
            grid.setWidget(2, 0, new LabelCampoForm("Fax"));
            grid.setWidget(3, 0, new LabelCampoForm("Endereco"));

            grid.setWidget(0, 1, new LabelCampoForm(to.getNome() != null ? to.getNome().trim() : ""));
            grid.setWidget(1, 1, new LabelCampoForm(to.getFone() != null ? to.getFone().trim() : ""));
            grid.setWidget(2, 1, new LabelCampoForm(to.getFax() != null ? to.getFax().trim() : ""));
            grid.setWidget(3, 1, new LabelCampoForm(to.getEndereco() != null ? to.getEndereco().trim() : ""));
        }
        return grid;
    }

    public static Grid montarGridAreas(final List<AreaTO> listTo) {
        Grid grid = new Grid(listTo.size(), 1);
        for (int i = 0; i < listTo.size(); i++) {
            grid.setWidget(i, 0, new LabelCampoForm(listTo.get(i).getNome()));
        }
        return grid;
    }
    
    public static Grid montarGridAvaliacoes (final List<AvaliacaoTO> listTo) {
        Grid grid = new Grid(listTo.size(), 2);
        grid.setBorderWidth(1);
 
        for (int i = 0; i < listTo.size(); i++) {        	
            grid.setWidget(i, 0, new LabelCampoForm(listTo.get(i).getStatus().getValue()));
            grid.setWidget(i, 1, new LabelCampoForm(listTo.get(i).getAvaliador().getPessoa().getNome()));
        }
        
        return grid;
    }

    public static Grid montarGridSubmissoes(final List<SubmissaoTO> listTo) {
        Grid grid = new Grid(listTo.size(), 2);
        for (int i = 0; i < listTo.size(); i++) {
            grid.setWidget(i, 0, new LabelCampoForm(listTo.get(i).getNomeArquivo()));
            grid.setWidget(i, 1, new LabelCampoForm(_dtTimeFormat.format(listTo.get(i).getDataSubmissao())));
        }
        return grid;
    }

    public static Grid montarGridAutores(final List<AutorTO> listTo) {
        Grid grid = new Grid(listTo.size(), 2);
        for (int i = 0; i < listTo.size(); i++) {
            grid.setWidget(i, 0, new LabelCampoForm(listTo.get(i).getPessoa().getSobreNome()+ ", " +listTo.get(i).getPessoa().getNome()));
            grid.setWidget(i, 1, new LabelCampoForm(" (" + listTo.get(i).getTipo() + " )"));
        }
        return grid;
    }

    public static Grid montarGridUsuario(final List<UsuarioTO> listTo) {
        Grid grid = new Grid(listTo.size(), 1);
        for (int i = 0; i < listTo.size(); i++) {
            grid.setWidget(i, 0, new LabelCampoForm(listTo.get(i).getPessoa().getNome()));
        }
        return grid;
    }

    public static Grid montarGridTrabalhos(final List<TrabalhoTO> listTo) {
        Grid grid = new Grid(listTo.size(), 2);
        for (int i = 0; i < listTo.size(); i++) {
            grid.setWidget(i, 0, new LabelCampoForm(listTo.get(i).getTitulo()));
            grid.setWidget(i, 0, new LabelCampoForm(listTo.get(i).getResumo()));
        }
        return grid;
    }
}
